package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper clueMapper;
    @Autowired
    private TbClueTrackRecordMapper recordMapper;


    /*
     *  新增线索跟进功能
     * */
    @Override
    public Integer addClueTrackRecord(ClueTrackRecordVo vo) {
        // 拆分出线索表实体和线索跟进表实体
        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(vo, tbClue);
        tbClue.setId(vo.getClueId());//设置id
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());//跟进中
        TbClueTrackRecord record = new TbClueTrackRecord();
        BeanUtils.copyProperties(vo, record);
        record.setCreateTime(DateUtils.getNowDate());//修改现在时间
        record.setCreateBy(SecurityUtils.getUsername());//设置跟进人
        // 修改线索表tb_clue
        clueMapper.updateTbClue(tbClue);
        // 新增线索跟进表tb_clue_track_record
        return recordMapper.insertTbClueTrackeRecord(record);
    }


    /*
    *  跟进线索id查询线索跟进记录列表
    * */
    @Override
    public List<?> selectTbClueTrackRecordList(Long clueId) {
        return recordMapper.getTbClueTrackRecordList(clueId);
    }

}
